var $path=$("#webPath").val();
$(function(){
    //主机群组的左移
	$("#add").click(function () {
		var groupids = $("#groupids");
		var groupList =  $("#groupNameList > option:selected");
		groupids.append(groupList);
	});
	
	//主机群组的右移
	$("#remove").click(function() {
		var groupNameList = $("#groupNameList");
		var groupList =  $("#groupids > option:selected");
		groupNameList.append(groupList);
	})
    //点击关闭按钮
    $('.press_btn2.Close').click(function(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    })
    $('.press_btn1').click(function(){
    	save();
    })
//    init();
});
//function init(){
//	var relation = eval("(" + $("#hidRelation").val() + ")");
//	$("#rid").val(relation.relationId);
//	$("#rname").val(relation.name);
//	$("#typeName option").each(function() {
//		if ($(this).val() == relation.relationType) {
//			$(this).attr("selected", "selected");
//		}
//	});
//	$("input[name='directionRadio']").each(function() {
//		if ($(this).val() == relation.directionFlag) {
//			$(this).attr("checked", "checked");
//		}
//	});
//	$("input[name='endRadio']").each(function() {
//		if ($(this).val() == relation.multideviceFlag) {
//			$(this).attr("checked", "checked");
//		}
//	});
//}
function save() {
	var hostid = $("#hostid").val();
	var host = $("input[name='host']").val();
    var name = $("input[name='name']").val();
    var proxy_hostid = $("input[name='proxy_hostid']").val();
    var status = $("input[name='status']:checked").val();

	 //将被选中的groupid值传到后台
    var groupids = new Array();
    var groupidList = $("#groupids > option");
    $.each(groupidList, function(i, obj) {
    	groupids[i]=$(obj).val();
    });
    
    //获取接口对象的参数值
    var interfaceid = $("#interfaceid").val();
    var ip = $("input[name='ip']").val();
    var dns = $("input[name='dns']").val();
    var useip = $("input[name='useip']").val();
    var port = $("input[name='port']").val();
    var type = $("#hostInterface > option:selected").val();
    
    
	if (name == "") {
		layer.msg("主机别名不能为空", {
			time : 1500
		});
		return;
	}
	$.ajax({
		url :  $path+"/radar/host/editHost.do",
		type : "post",
		dataType:"json",
		data : {
			"hostid" : hostid,
			"host" : host,
			"name" : name,
			"proxy_hostid" : proxy_hostid,
			"status" : status,
            //json不能传数组，需要转成字符串
            "groupids":groupids.join(","),
            "interfaceid":interfaceid,
            "ip":ip,
            "dns":dns,
            "useip":useip,
            "port":port,
            "type":type
		},
		success : function(json) {
			var result = json.errorMessage;
			if (result != null && result != "") {
				layer.msg(result);
			} else if (result == "") {
				layer.msg("修改失败!", {time:1000});
			}
			parent.paging(1);// 调用父窗口的方法
			var index = parent.layer.getFrameIndex(window.name);
			setTimeout('parent.layer.close('+index+')',1001);
		}
	});
}